﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System.ComponentModel;
using BrainTechLLC.ImageOperators;

namespace ImageAppViewModels
{
    public class FilterViewModel : INotifyPropertyChanged
    {
        
        protected ISingleFilter _filter;

        public FilterViewModel(ISingleFilter filter)
        {
            _filter = filter;            
        }

        public string FilterType
        {
            get { return _filter.Name; }
        }

        public string TypeName
        {
            get { return _filter.Name; }
        }

        public FilterStatus Status
        {
            get
            {
                return _filter.Status;
            }
            set
            {
                if (_filter.Status != value)
                {
                    _filter.Status = value;
                    OnPropertyChanged("Status");
                }
            }
        }

        public string ActiveOrDisabled
        {
            get { return Active ? "Active" : "Disabled"; }
        }

        public bool Active
        {
            get { return !Disabled; }
            set
            {
                if (Disabled != !value)
                {
                    Disabled = !value;
                    OnPropertyChanged("Disabled");
                    OnPropertyChanged("Active");
                    OnPropertyChanged("ActiveOrDisabled");
                }
            }
        }

        public bool TempNotActive
        {
            get { return (_filter.Status & FilterStatus.TempNotActive) == FilterStatus.TempNotActive; }
            set
            {
                if (TempNotActive != value)
                {
                    if (value)
                    {
                        _filter.Status |= FilterStatus.TempNotActive;
                    }
                    else
                    {
                        _filter.Status &= ~FilterStatus.TempNotActive;
                    }

                    OnPropertyChanged("TempNotActive");
                    OnPropertyChanged("Disabled");
                    OnPropertyChanged("Active");
                    OnPropertyChanged("ActiveOrDisabled");
                }
            }
        }

        public bool TempActive
        {
            get { return (_filter.Status & FilterStatus.TempActive) == FilterStatus.TempActive; }
            set
            {
                if (TempActive != value)
                {
                    if (value)
                    {
                        _filter.Status |= FilterStatus.TempActive;
                    }
                    else
                    {
                        _filter.Status &= ~FilterStatus.TempActive;
                    }

                    OnPropertyChanged("TempActive");
                    OnPropertyChanged("Disabled");
                    OnPropertyChanged("Active");
                    OnPropertyChanged("ActiveOrDisabled");
                }
            }
        }

        public bool Disabled
        {
            get
            {
                return (_filter.Status & FilterStatus.Disabled) == FilterStatus.Disabled;
            }
            set
            {
                if (Disabled != value)
                {
                    if (value)
                    {
                        _filter.Status |= FilterStatus.Disabled;
                    }
                    else
                    {
                        _filter.Status &= ~FilterStatus.Disabled;
                    }

                    OnPropertyChanged("Disabled");
                    OnPropertyChanged("NotDisabled");
                }
            }
        }

        public ISingleFilter Filter { get { return _filter; } }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
